package com.generator.security.exception;

import cn.hutool.json.JSONUtil;
import com.generator.utils.Result;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @version 1.0
 * @Author Xing
 * @Date 2023/12/5 14:40
 */
public class SecurityAuthenticationEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException{
        response.setContentType("application/json;charset=UTF-8");
        response.addHeader(  "Access-Control-Allow-Origin","*");
        response.getWriter().print(JSONUtil.parse(new Result().err(401)));
    }
}
